package com.fq.wechat.service.impl;

import com.fq.wechat.dao.CC3200DAO;
import com.fq.wechat.domain.SensorDO;
import com.fq.wechat.service.CC3200Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jifang.
 * @since 2016/4/3 15:47.
 */
@Service
public class CC3200ServiceImpl implements CC3200Service {

    @Autowired
    private CC3200DAO dao;

    @Override
    public void initSensor(String sequence) {
        dao.insertSensor(sequence);
    }

    @Override
    public void removeSensor(String sequence) {
        dao.deleteSensor(sequence);
    }

    @Override
    public void saveSensor(SensorDO sensor, String sequence) {
        sensor.setSequence(sequence);
        dao.updateSensor(sensor);
    }
    
    @Override
    public SensorDO getSensor(String sequence) {
        return dao.selectSensorBySequence(sequence);
    }

    @Override
    public void saveTemperature(String temperature, String sequence) {
        SensorDO sensor = new SensorDO();
        sensor.setTemperature(temperature);
        sensor.setSequence(sequence);
        dao.updateSensor(sensor);
    }

    @Override
    public String getTemperature(String sequence) {
        return dao.selectSensorBySequence(sequence).getTemperature();
    }

    @Override
    public void saveLight(String light, String sequence) {
        SensorDO sensor = new SensorDO();
        sensor.setSequence(sequence);
        sensor.setLight(light);
        dao.updateSensor(sensor);
    }

    @Override
    public String getLight(String sequence) {
        return dao.selectSensorBySequence(sequence).getLight();
    }

    @Override
    public void saveFan(String fan, String sequence) {
        SensorDO sensor = new SensorDO();
        sensor.setSequence(sequence);
        sensor.setFan(fan);
        dao.updateSensor(sensor);
    }

    @Override
    public String getFan(String sequence) {
        return dao.selectSensorBySequence(sequence).getFan();
    }

    @Override
    public void saveHumidity(String humidity, String sequence) {
        SensorDO sensor = new SensorDO();
        sensor.setHumidity(humidity);
        sensor.setSequence(sequence);
        dao.updateSensor(sensor);
    }

    @Override
    public String getHumidity(String sequence) {
        return dao.selectSensorBySequence(sequence).getHumidity();
    }
}
